package com.ziytek.web.citizen.model.req;

import com.ziytek.web.citizen.constant.ServerConstant;
import com.ziytek.web.citizen.util.StringUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.apache.commons.lang3.time.DateUtils;

import java.util.Date;

/**
 * @author fenghx
 * @version v1.0
 * @className QueryBatteriesD
 * @descripton 充放电实时曲线数据导出通知接口
 * @date 2023/4/20 14:23
 **/
@Data
@Slf4j
//@Tag(name = "充放电实时曲线数据导出通知接口")
public class BatteryExportNotifyReq {
    /**
     * 用户token
     */
    //@Schema(name = "用户token", required = true)
    private String token;

    /**
     * 机柜编号
     */
    //@Schema(name = "机柜编号", required = true)
    private String cabinetNo;

    /**
     * 导出文件名 格式: yyyy-MM-dd HH:mm:ss 对应工步执行时间
     */
    //@Schema(name = "导出文件名(导出文件名 格式: yyyy-MM-dd HH:mm:ss) 格式: yyyy-MM-dd HH:mm:ss", required = true)
    private String exportFileName;

    public void requestCheckFileName() {
        if (StringUtil.isEmpty(this.exportFileName)) {
            this.exportFileName = "电芯曲线实时数据导出_" + DateFormatUtils.format(System.currentTimeMillis(), ServerConstant.DATE_FORMAT_TIME_STR);
        }
    }

    /**
     * @param dbName yyyyMMddHHmmss
     * @return name
     */
    public String fileName(String dbName) {
        Date date;
        String fileName = "";
        if (!StringUtil.isEmpty(dbName)) {
            try {
                date = DateUtils.parseDate(dbName, ServerConstant.DATE_FORMAT_TWO);
                fileName = DateFormatUtils.format(date, ServerConstant.DATE_FORMAT_TWO);
            } catch (Exception e) {
                log.error("日期格式错误,请检查日期格式是否正确,格式: yyyy-MM-dd HH:mm:ss");
            }
        }

        if (StringUtil.isEmpty(this.exportFileName) && !StringUtil.isEmpty(fileName)) {
            this.exportFileName = fileName;
        }

        if (!StringUtil.isEmpty(this.exportFileName)) {
            try {
                date = DateUtils.parseDate(this.exportFileName, ServerConstant.DATE_FORMAT);
                this.exportFileName = DateFormatUtils.format(date, ServerConstant.DATE_FORMAT_TWO);
            } catch (Exception e) {
                log.error("日期格式错误,请检查日期格式是否正确,格式: yyyy-MM-dd HH:mm:ss");
            }
        }

        return this.exportFileName;
    }

}
